'use strict';

module.exports = app => {
  const mongoose = app.mongoose;
  const Schema = mongoose.Schema;

  const MessageSchema = new Schema({
    type: {type: String},
    master_id: {type: String}, // 收到消息的人
    master_name: {type: String},
    author_id: {type: String}, // 发送消息的人
    author_name: {type: String},
    topic_id: {type: String},
    topic_title: {type: String},
    reply_id: {type: String},
    has_read: {type: Boolean, default: false},
  }, {timestamps: true});

  MessageSchema.index({master_id: 1, has_read: -1, createdAt: -1});

  return mongoose.model('Message', MessageSchema, 'messages');
};
